﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MVVMFramework.ViewModel
{
    public abstract class PropertyValidatorBase : IPropertyValidator
    {
        protected readonly Expression<Func<object>> Property;

        private Func<object> propertyCompiled;
        protected Func<object> PropertyCompiled
        {
            get
            {
                if (propertyCompiled == null)
                    propertyCompiled = Property.Compile();

                return propertyCompiled;
            }
        }

        protected PropertyValidatorBase(Expression<Func<object>> property, string message)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            Property = property;
            PropertyName = NotifyPropertyChangedBase.GetPropertyName(property);
            this.message = message;
        }

        public string PropertyName
        {
            get;
            private set;
        }

        public abstract bool IsValid
        {
            get;
        }

        public abstract string ShortMessage
        {
            get;
        }

        private readonly string message;
        public virtual string Message
        {
            get
            {
                return message;
            }
        }
    }
}
